package org.test.character.socket;

import java.io.BufferedReader;
import org.apache.commons.lang.SerializationUtils;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Date;
import javax.net.SocketFactory;



public class ClientSock {

	public static void main(String args[]) throws Exception {
		// System.setProperty("javax.net.ssl.trustStore", "d:/mykeystore");
		// SSLSocketFactory ssf = (SSLSocketFactory)
		// SSLSocketFactory.getDefault();

		SocketFactory ssf = SocketFactory.getDefault();

		//Socket s = ssf.createSocket("192.168.4.206", 8998);
		Socket s = ssf.createSocket("127.0.0.1", 5410);
		// 等待输入　
		BufferedReader bReader = new BufferedReader(new InputStreamReader(
				System.in));
		
		while (true) {		//客户端运行
			String string = bReader.readLine();
			if (string.equals("quit")) {
				s.close();
				return;
			}
			if(CustommerUtil.testData(string)==-1){//输入有误
				System.out.println("输入有误,请输入大于2的数或quit");
				continue;
			}
			
		/*	
			//传送bytes
			FileOutputStream sos = (FileOutputStream) s.getOutputStream();
			sos.write(string.getBytes());
			sos.flush();
			
			
			//接收回复
			BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			System.out.println(br.readLine());*/
			
			
			/**尝试发送对象过去,以Date为例*/
			Date date = new java.util.Date();
			System.out.println(date);
			byte[] datebyte = SerializationUtils.serialize(date);
			FileOutputStream sos = (FileOutputStream) s.getOutputStream();
			sos.write(datebyte);
			sos.flush();
			
		}
	}


}
